
#include <stdio.h>
#include "itcpclient.h"
#include "tools/tools.h"
#include "errorcode.h"
#define SERVER_CONNECT_IDX -1
int main()
{
	TimerStart();
	ITCPClient* Client = CreateTCPClient();
	if ( !Client )
		return 1;

	char szTemp[512] = "Hello Server!\n"; 
	Client->StartClient( "127.0.0.1", 3345 );
	for( int i = 0; i < 20; i++ )
	{
		Sleep( 500 );
		OutPutDebugStringToCMD( "Try To Connect Server\n" );
		if( errcode::enFunctionReturnValue_Sucess == Client->ConnectToServer() )
		{
			OutPutDebugStringToCMD( "Connect Server Sucess\n" );
			break;
		}
	}

	int i = 0;
	while( 1 )
	{
		unsigned int RecvSize = 0;
		sprintf_s(szTemp, "helloServer(%04d)",i);
		Sleep( 1000 );
		OutPutDebugStringToCMD( "Send Msg:%s\n", szTemp );
		Client->PushDataToSendBuff(SERVER_CONNECT_IDX,  szTemp, strlen( szTemp ) );

		char *recvData = (char*)Client->GetDataFromRecvBuff(RecvSize);
		if (RecvSize > 0)
		{
			OutPutDebugStringToCMD(recvData+4);
		}
		i++;
	}


	//

	getchar();
	Client->StopClient();
	return 0;
}